﻿using Students;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace CourseTests
{
    [TestClass]
    public class CourseTest
    {
        private TestContext testContextInstance;
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestMethod]
        public void AddStudentTest()
        {
            Course target = new Course(); // TODO: Initialize to an appropriate value
            target.AddStudent("Ivan", 12341);
            Assert.IsNotNull(target.Students[12341]);
            Assert.AreEqual(target.Students[12341].Name, "Ivan");
        }
        [TestMethod]
        [ExpectedException(typeof(ArgumentException), "Name should not be empty")]
        public void AddEmptyStudentName()
        {
            Course target = new Course();
            target.AddStudent("", 13123);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException), "Faculty number should be between 10 000 and 99 999")]
        public void AddBadFacultyNumberStudent()
        {
            Course target = new Course();
            target.AddStudent("", 133123);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException), "Faculty number already exists in the database")]
        public void AddDuplicateStudentTest()
        {
            Course target = new Course(); // TODO: Initialize to an appropriate value
            target.AddStudent("Ivan", 12341);
            target.AddStudent("Ivan2", 12341);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException), "The course is full")]
        public void AddTooManyStudents()
        {
            Course target = new Course(); // TODO: Initialize to an appropriate value
            for (int i = 0; i < 32; i++)
            {
                target.AddStudent("wasd", 10000 + i);
            }
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException), "Faculty number should be between 10 000 and 99 999")]
        public void AddWronfFacNum()
        {
            Course target = new Course(); // TODO: Initialize to an appropriate value
            target.AddStudent("WASD", 123);
        }
        //--------------REMOVE

        [TestMethod()]
        public void RemoveStudentTest()
        {
            Course target = new Course(); // TODO: Initialize to an appropriate value
            target.AddStudent("Ivan", 12345);
            target.RemoveStudent(12345);
            Assert.IsFalse(target.Students.ContainsKey(12345));
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException), "The student is not enrolled in this course")]
        public void RemoveNonExistingStudent()
        {
            Course target = new Course(); // TODO: Initialize to an appropriate value
            target.AddStudent("Ivan", 12341);
            target.RemoveStudent(92241);
        }
    }
}
